<template>
  <div class="h-full">
    <img src="@/assets/background.jpg" alt="" />
    <img class="w-20 h-20 mx-auto -mt-10" src="../assets/logo.png" />
    <van-form @submit="onSubmit" class="mt-8 mx-8">
      <van-field
        class="py-4"
        v-model="username"
        name="username"
        label="用户名"
        placeholder="请输入用户名"
        clearable
        :rules="[{ required: true, message: '' }]"
      />
      <van-field
        class="py-4"
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="请输入密码"
        clearable
        :rules="[{ required: true, message: '' }]"
      />
      <div class="mt-8 mx-4">
        <van-button block type="primary" native-type="submit">注 册</van-button>
      </div>
      <p class="mt-4 text-center text-sm">
        已有账号？
        <span class="text-blue-400" @click="$router.push('/login')">
          返回登录
        </span>
      </p>
    </van-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: 'vet',
      password: 'password',
    }
  },
  methods: {
    onSubmit(values) {
      console.log('submit', values)
      this.axios.post('/register', values).then(res => {
        if (res.data.msg == 'ok') {
          this.$toast.success('注册成功')
          this.$router.push('/login')
        } else {
          this.$toast.fail(res.data.msg)
        }
      })
    },
  },
}
</script>
